package com.culture.bootdemo.service.impl;

import com.culture.bootdemo.dao.AnswerMapper;
import com.culture.bootdemo.po.Answer;
import com.culture.bootdemo.service.AnswerService;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author wen
 * @date Created in 2019/8/13
 * @Description
 **/
@Service
public class AnswerServiceImpl implements AnswerService {
    private static final ExecutorService EXECUTOR = new ThreadPoolExecutor(8, 9, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), new ThreadFactoryBuilder().setNameFormat("demo-pool-%d").build());


    @Autowired
    public AnswerMapper answerMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addtest() {

        System.out.println("1111");
        answerMapper.insert(new Answer(5, "eee"));
        int i = 1 / 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void testDate(int taskId) {
        for (int j = 10; j <= 13; j++) {
            if (taskId == 2 && j == 12) {
                int a = 1 / 0;
            }
            answerMapper.insert(new Answer(j * taskId, "jjjjj"));
        }
        answerMapper.insert(new Answer(taskId, "iiiii"));
    }

}
